﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace HDJ.Framework.Core
{
    public class CommendWindow : MonoBehaviour
    {
        public Text Text_Content;
        public InputField InputField;
        public ScrollRect ScrollView;

        public Button Button_keepBottom;
        public Button Button_Exit;
        public GameObject Buttons;

        private bool isKeepBottomScrollView;
        // Start is called before the first frame update
        void Start()
        {
            Init();
        }

        public void Init()
        {
            Text_Content.text = "";
            OnButton_keepBottom();
            Buttons.SetActive(false);
        }
        // Update is called once per frame
        void Update()
        {
            if (isKeepBottomScrollView)
                ScrollView.verticalNormalizedPosition = 0;
        }
        public void OnScrollViewChange(Vector2 v2)
        {
            //if (ScrollView.verticalNormalizedPosition != 0)
            //    isKeepBottomScrollView = false;
            //else
            //    isKeepBottomScrollView = true;
        }
        public void OnInputEnd(string t)
        {
            if (string.IsNullOrEmpty(InputField.text))
                return;
            AddLineText(">" + InputField.text);
            InputField.text = "";
            InputField.ActivateInputField();
        }

        public void AddLineText(string content)
        {
            Text_Content.text += content + "\n";
            //if (isKeepBottomScrollView)
            //    ScrollView.verticalNormalizedPosition = 0;
        }

        public void OnButton_keepBottom()
        {
            isKeepBottomScrollView = !isKeepBottomScrollView;
            Image image = Button_keepBottom.GetComponent<Image>();
            if (isKeepBottomScrollView)
            {
                image.color = new Color(241 / 255f, 131 / 255f, 33 / 255f, 1);
            }
            else
            {
                image.color = Color.white;
            }
        }
        public void OnButton_Exit()
        {
            gameObject.SetActive(false);
        }
        public void OnButton_Functions()
        {
            Buttons.SetActive(!Buttons.activeSelf);
        }
    }
}
